# coding:utf-8
from PySide6.QtGui import QIcon, QColor
from PySide6.QtWidgets import QApplication
from qfluentwidgets import FluentWindow

from common import NavigationIcon, cfg
from .discover_interface import DiscoverInterface
from .favorite_interface import FavoriteInterface
from .leaderboard_interface import LeaderboardInterface
from .list_interface import ListInterface
from .member_interface import MemberInterface
from .playlist_interface import PlaylistInterface
from .sort_interface import SortInterface


class MainInterface(FluentWindow):

    def __init__(self):
        super().__init__()
        # create sub interface
        self.discoverInterface = DiscoverInterface(self)
        self.sortInterface = SortInterface(self)
        self.listInterface = ListInterface(self)
        self.leaderboardInterface = LeaderboardInterface(self)
        self.memberInterface = MemberInterface(self)
        self.playlistInterface = PlaylistInterface(self)
        self.favoriteInterface = FavoriteInterface(self)

        self.initNavigation()
        self.initWindow()

    def initNavigation(self):
        self.addSubInterface(self.discoverInterface, NavigationIcon.Menu, '发现', isTransparent=True)
        self.addSubInterface(self.sortInterface, NavigationIcon.Library, '分类', isTransparent=True)
        self.addSubInterface(self.listInterface, NavigationIcon.History, '播放列表', isTransparent=True)
        self.addSubInterface(self.leaderboardInterface, NavigationIcon.Statistics, '排行榜', isTransparent=True)
        self.addSubInterface(self.memberInterface, NavigationIcon.Card, '会员中心', isTransparent=True)
        # self.navigationInterface.addSeparator()
        self.navigationInterface.addItem('创建播放列表', NavigationIcon.Plus, '创建播放列表',
                                         lambda x: print('create playlist'), selectable=False)
        # self.addSubInterface(self.playlistInterface, NavigationIcon.Plus, '创建播放列表', isTransparent=True)
        self.addSubInterface(self.favoriteInterface, NavigationIcon.Heart, '我的喜欢', isTransparent=True)

    def initWindow(self):
        self.setMinimumSize(1200, 1000)
        self.setWindowIcon(QIcon('resource/logo.png'))
        self.setWindowTitle('Music Library Player')
        self.setCustomBackgroundColor(QColor(240, 244, 249), QColor(32, 32, 32))
        self.setMicaEffectEnabled(cfg.get(cfg.micaEnabled))

        desktop = QApplication.screens()[0].availableGeometry()
        w, h = desktop.width(), desktop.height()
        self.move(w // 2 - self.width() // 2, h // 2 - self.height() // 2)
